#!/usr/bin/env python3
import mysql.connector
from mysql.connector import Error
import os


def clear_stress_test_status():
    # 从环境变量获取数据库连接信息（更安全）
    host = os.getenv("MYSQL_HOST")
    user = os.getenv("MYSQL_USER")
    password = os.getenv("MYSQL_PASSWORD")
    database = os.getenv("MYSQL_DATABASE")

    try:
        conn = mysql.connector.connect(
            host=host,
            user=user,
            password=password,
            database=database
        )

        if conn.is_connected():
            print(f"✅ 已连接到数据库 {database} ({host})")
            cursor = conn.cursor()
            cursor.execute("TRUNCATE TABLE stress_test_status;")
            conn.commit()
            print("✅ stress_test_status 表已清空")
    except Error as e:
        print(f"❌ 数据库操作失败: {e}")
    finally:
        if conn.is_connected():
            cursor.close()
            conn.close()
            print("✅ 数据库连接已关闭")


if __name__ == "__main__":
    clear_stress_test_status()
